<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-business__device}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.deviceNo" placeholder="设备编号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.institution" placeholder="所属单位" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.position" placeholder="位置" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.coordinateX" placeholder="X坐标" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.coordinateY" placeholder="Y坐标" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" placeholder="状态" clearable>
            <el-option label="状态" value=""></el-option>
            <el-option label="开启" value="1"></el-option>
            <el-option label="关闭" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.phone" placeholder="联系电话" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('business:device:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('business:device:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="deviceNo" label="设备编号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="institution" label="所属单位" header-align="center" align="center"></el-table-column>
        <el-table-column prop="position" label="位置" header-align="center" align="center"></el-table-column>
        <el-table-column prop="coordinateX" label="X坐标" header-align="center" align="center"></el-table-column>
        <el-table-column prop="coordinateY" label="Y坐标" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 1" size="small" type="primary">开启</el-tag>
            <el-tag v-else-if="scope.row.status === 0" size="small" type="primary">关闭</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="联系电话" header-align="center" align="center"></el-table-column>
        <!--
        <el-table-column prop="parameter" label="用电参数" header-align="center" align="center"></el-table-column>
        <el-table-column prop="alarmRecord" label="报警记录" header-align="center" align="center"></el-table-column>
        <el-table-column prop="runRecord" label="运行记录" header-align="center" align="center"></el-table-column>
        -->
        <el-table-column prop="voltage" label="电压(V)" header-align="center" align="center"></el-table-column>
        <el-table-column prop="current" label="电流(A)" header-align="center" align="center"></el-table-column>
        <el-table-column prop="meterValue" label="抄表值(KWH)" header-align="center" align="center"></el-table-column>
        <el-table-column prop="rtg" label="对地电阻(Ω)" header-align="center" align="center"></el-table-column>
        <el-table-column prop="leakageCurrent" label="漏电流(mA)" header-align="center" align="center"></el-table-column>
        <!--
        <el-table-column prop="repairPhone" label="维修电话" header-align="center" align="center"></el-table-column>
        -->
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('business:device:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('business:device:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './device-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/business/device/page',
        getDataListIsPage: true,
        deleteURL: '/business/device',
        deleteIsBatch: true
      },
      customerDemoCreateTime: '',
      customerCreateTime: '',
      customerActivatedTime: '',
      dataForm: {
        deviceId: '',
        customerNo: '',
        customerNoDemo: '',
        chineseName: '',
        phone: '',
        accountType: '',
        deviceWrong: '',
        accountWrong: '',
        customerDemoCreateStartTime: '',
        customerDemoCreateEndTime: '',
        customerCreateStartTime: '',
        customerCreateEndTime: '',
        customerActivatedStartTime: '',
        customerActivatedEndTime: ''
      }
    }
  },
  watch: {
    customerDemoCreateTime (val) {
      if(val){
        this.dataForm.customerDemoCreateStartTime = new Date(val[0]).getTime()
        this.dataForm.customerDemoCreateEndTime = new Date(val[1]).getTime()
      }else{
        this.dataForm.customerDemoCreateStartTime =''
        this.dataForm.customerDemoCreateEndTime =''
      }
    },
    customerCreateTime (val) {
      if(val){
        this.dataForm.customerCreateStartTime = new Date(val[0]).getTime()
        this.dataForm.customerCreateEndTime = new Date(val[1]).getTime()
      }else{
        this.dataForm.customerCreateStartTime =''
        this.dataForm.customerCreateEndTime =''
      }
    },
    customerActivatedTime (val) {
      if(val){
        this.dataForm.customerActivatedStartTime = new Date(val[0]).getTime()
        this.dataForm.customerActivatedEndTime = new Date(val[1]).getTime()
      }else{
        this.dataForm.customerActivatedStartTime =''
        this.dataForm.customerActivatedEndTime =''
      }
    }
  },
  components: {
    AddOrUpdate
  }
}
</script>
